﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;

/// <summary>
///Register 的摘要说明
/// </summary>
public class Register
{
    private SqlCommand cmd;
    private SqlTransaction tran;
	public Register()
	{
		//
		//TODO: 在此处添加构造函数逻辑
		//
	}
    public string register(TBperson tbp)
    {
        string result = "0";
        try
        {
            cmd = new SqlCommand();
            cmd.Connection = ConDB.GetOpen();
            cmd.CommandText = "register";
            cmd.CommandType = CommandType.StoredProcedure;
            tran = cmd.Connection.BeginTransaction();
            cmd.Transaction = tran;
            cmd.Parameters.Add("@pid", SqlDbType.VarChar, 20).Value = tbp.Pid;
            cmd.Parameters.Add("@pname", SqlDbType.VarChar,10).Value = tbp.Pname;
            cmd.Parameters.Add("@ppwd", SqlDbType.VarChar, 100).Value = tbp.Ppwd;
            cmd.Parameters.Add("@psex", SqlDbType.VarChar, 5).Value = tbp.Psex;
            cmd.Parameters.Add("@page", SqlDbType.VarChar, 3).Value = tbp.Page;
            cmd.Parameters.Add("@padd", SqlDbType.VarChar, 50).Value = tbp.Padd;
            cmd.Parameters.Add("@phouseholder", SqlDbType.Char,50).Value = tbp.Phouseholder;
            cmd.Parameters.Add("@ptel", SqlDbType.VarChar, 20).Value = tbp.Ptel;
            cmd.Parameters.Add("@pmail", SqlDbType.VarChar, 30).Value = tbp.Pemail;
            cmd.Parameters.Add("@pschool", SqlDbType.VarChar, 30).Value = tbp.Pschool;
            cmd.Parameters.Add("@pknowledge", SqlDbType.VarChar,30).Value = tbp.Pknowledge;
            cmd.ExecuteNonQuery();
                result = "1";
                tran.Commit();
        }
        catch (Exception e)
        {
            result = "0";
            tran.Rollback();
        }
        finally
        {
            ConDB.Close();
        }
        return result;
    }
    public string autoID()
    {
        string result = "";
        try
        {
            cmd = new SqlCommand("select max(pid) from tb_person", ConDB.GetOpen());
            string i = cmd.ExecuteScalar().ToString();
            if (i.Equals(""))
            {
                result = DateTime.Now.ToString("yyyyMMdd") + "1001";

            }
            else
            {
                result = DateTime.Now.ToString("yyyyMMdd") + (Convert.ToInt32(i.Substring(8)) + 1).ToString();//当有记录时加一
            }
        }
        catch
        {
            result = "";
        }
        finally
        {

            ConDB.Close();
        }
        return result;
    }
}
